using UnityEngine;
using UnityEditor;

public class EnvironmentSelector : EditorWindow
{
    private static EnvironmentSettings settings;
    private const string settingsPath = "Assets/Resources/EnvironmentSettings.asset";

    [MenuItem("Tools/Environment Selector")]
    public static void ShowWindow()
    {
        GetWindow<EnvironmentSelector>("Environment Selector");
    }

    private void OnEnable()
    {
        settings = AssetDatabase.LoadAssetAtPath<EnvironmentSettings>(settingsPath);
        if (settings == null)
        {
            settings = CreateInstance<EnvironmentSettings>();
            AssetDatabase.CreateAsset(settings, settingsPath);
            AssetDatabase.SaveAssets();
        }
    }

    private void OnGUI()
    {
        GUILayout.Label("Select Environment", EditorStyles.boldLabel);
        settings.currentEnvironment = (YooAssetEnvironmentType)EditorGUILayout.EnumPopup("Environment", settings.currentEnvironment);

        if (GUILayout.Button("Save Environment"))
        {
            EditorUtility.SetDirty(settings);
            AssetDatabase.SaveAssets();
            Debug.Log("Selected Environment Saved: " + settings.currentEnvironment);
        }
    }
}